package com.itlong.cloud.commons;

import com.itlong.cloud.iottp.IIotTpSmsServiceClient;
import com.itlong.cloud.noncore.commons.ITimeTaskOfOperationLogServiceClient;
import com.itlong.cloud.utils.date.DateUtil;
import com.itlong.cloud.utils.network.http.HttpProtocolUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.web.bind.annotation.RestController;

import java.util.Calendar;

/**
 * <desc>
 *      创建项目服务心跳检测
 * </desc>
 *
 * @createDate 2020/07/28
 */
@EnableScheduling // 启用定时任务
@RestController
public class CreateProjectHeartTimeTask {

    private static Logger LOG = LoggerFactory.getLogger(CreateProjectHeartTimeTask.class);

    private final String statusProjectUrl = "http://www.itlongoa.com.cn:8099/api/project_info/status";//心跳地址url

    private final String phone = "18126126601";//运维电话

    private final String content = "旺龙创建项目服务异常,无法与旺龙云服务通信,请查看";//短信内容

    @Autowired
    IIotTpSmsServiceClient iIotTpSmsServiceClient;

    /**
     * <desc>
     *      创建项目服务心跳检测
     * </desc>
     *
     * @author Qiang.S
     * @createDate 2020/07/28
     */
    @Scheduled(cron = "0 0 * * * ?")   // 1个小时执行一次
    public void timeTaskRegularCleanData() {
        try {
            HttpProtocolUtil.doGet(statusProjectUrl, null);
        } catch (Exception e) {
            LOG.info("创建项目服务无法连接");
            iIotTpSmsServiceClient.sendSmsCodeByPhone(phone, content);
        }
    }

}
